package com.ricohgag.util;

import java.util.Random;

/**
 * @author ricohgag
 * @date 2018/8/27 11:13
 */
public class CodeUtil {
    public static String getCodeString(){
        int codeLen =  4;
        String[] strings = new String[62];
        for(int i=0;i<26;i++){
            strings[i] = Character.valueOf((char) ('a'+i)).toString();
        }
        for(int i=0,j=26;i<26;i++,j++){
            strings[j] = Character.valueOf((char) ('A'+i)).toString();
        }
        for(int i=0,j=52;i<10;i++,j++){
            strings[j] = Character.valueOf((char) ('0'+j)).toString();
        }

        StringBuffer sb = new StringBuffer();
        Random random = new Random();

        for(int i=0, stringsLen=strings.length;i<codeLen;i++){
            sb.append(strings[random.nextInt(stringsLen)]);
        }
        return sb.toString();
    }
}
